import requests

# request GET初体验
# resp = requests.get('https://www.baidu.com/')
# print(type(resp))
# print(resp.status_code)
# print(type(resp.text))
# print(resp.text)
# print(resp.cookies)

# request GET请求
# data = {
#     'name': 'germey',
#     'age': '22'
# }
# r = requests.get('http://httpbin.org/get', params=data)
# print(r.text)

# 抓取网页
# headers = {
#     'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko)Chrome/52.0.2743.116 Safari/537.36'
# }
# r = requests.get("https://www.zhihu.com/explore", headers=headers)
# pattern = re.compile('explore-feed.*?question_link.*?>(.*?)</a>', re.S)
# titles = re.findall(pattern,r.text)
# print(titles)

# 抓取二进制数据
# r = requests.get("https://github.com/favicon.ico")
# with open('favicon.ico', 'wb') as f:
#     f.write(r.content)

# POST
data = {
    'name':'ccccc'
}
r = requests.post('http://httpbin.org/post',data=data)
print(r.text)